package com.sy.dao.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.sy.sql.DataBaseConnection;

public class PageCount {

	public int count(String tableName) {
		int intRowCount = 0;//总行数
		PreparedStatement pstmt	= null ;
		String sql				= null ;
		ResultSet rs			= null ;
		DataBaseConnection dbc= new DataBaseConnection() ;
		sql = "select count(id) from "+tableName+" order by id asc";
		try
		{			
			pstmt = dbc.getConnection().prepareStatement(sql);
			rs = pstmt.executeQuery();
			rs.next();//游标指向第一行
			intRowCount=rs.getInt(1);//取得总行数
			rs.close();
			pstmt.close();
		}
		catch(Exception e)
		{
			System.out.println(e) ;
		}
		finally
		{
			dbc.close();
		}
		return intRowCount;
	}
}
